package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.LogRequest;
import com.bodu.system.entity.vo.LogVo;
import com.bodu.system.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日志管理 Biz
 *
 * @author gaoya
 * @since 2019-06-08
 */
@Api(tags = "日志管理")
@RestController
@RequestMapping("/log")
public class LogController extends AbstractCommonController<LogService, LogRequest, LogVo> {

    private final LogService logService;

    public LogController(LogService logService) {
        this.logService = logService;
    }

    @TraceLog()
    @GetMapping("id")
    @ApiOperation("得到日志详情")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(logService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存日志信息")
    public Result save(@RequestBody LogRequest logRequest) {
        return super.save(logService, logRequest);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新日志信息")
    public Result update(@RequestBody LogRequest logRequest) {
        return super.update(logService, logRequest);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("日志信息-列表")
    public Result listPage(@RequestBody ParamReq<LogRequest> req) {
        return super.listPage(logService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("日志信息-统计")
    public Result countPage(@RequestBody ParamReq<LogRequest> req) {
        return super.countPage(logService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("日志信息-分页")
    public Result page(@RequestBody ParamReq<LogRequest> req) {
        return super.page(logService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除日志记录")
    public Result delete(@PathVariable("id") Long id) {
        return super.delete(logService, id);
    }

    @TraceLog()
    @DeleteMapping("{ids}")
    @ApiOperation("批量删除日志记录")
    public Result batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(logService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
